package cn.bmyi.webautotest.baidudemo;

import cn.bmyi.webautotest.aimee.BrowserEmulator;
import cn.bmyi.webautotest.aimee.BrowserEmulator.Element;

/**
 * 封装搜索结果页面元素和操作
 * 
 * @author 毛建杰
 *
 */
public class ResultPage
{
	public BrowserEmulator browser;
	public String url;

	private static class PageElement
	{
		public static final String BAIDU_LOGO_ID = "logo"; // 百度Logo
		public static final String SEARCH_REAULTS_CLASS = "c-result"; // 搜索结果
	}

	public ResultPage(BrowserEmulator browser)
	{
		this.browser = browser;
		this.url = browser.getUrl();
	}

	/**
	 * 判断Logo是否显示
	 * 
	 * @return True：已显示；False：未显示
	 */
	public boolean isLogoDisplayed()
	{
		try
		{
			browser.findElement("id", PageElement.BAIDU_LOGO_ID);
			return true;
		}
		catch (Exception e)
		{
			return false;
		}
	}

	/**
	 * 获取搜索结果
	 * 
	 * @return 搜索结果
	 */
	public String[] getSearchResults()
	{
		Element[] searchResults = browser.findElements("className", PageElement.SEARCH_REAULTS_CLASS);
		String[] ret = new String[searchResults.length];
		for (int i = 0; i < searchResults.length; i++)
		{
			ret[i] = searchResults[i].getText();
		}
		return ret;
	}
}
